package logic

import (
	"context"
	"furni-link/furnirpc/furnirpc"
	"furni-link/furnirpc/internal/svc"
	"furni-link/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type FurnAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFurnAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FurnAddLogic {
	return &FurnAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FurnAddLogic) FurnAdd(in *furnirpc.FurnAddRequest) (*furnirpc.FurnAddResponse, error) {
	// todo: add your logic here and delete this line

	//var listFurn mysql.Furn
	//mysql.DB.Debug().Where("brandId = ?", in.BrandId).Find(&listFurn)
	//
	//if listFurn.ID == 0 {
	//	return nil, errors.New("品牌不存在")
	//}

	furn := mysql.Furn{
		FurnName: in.FurnName,
		Price:    float64(in.Price),
		Num:      int(in.Num),
		ClassId:  int(in.ClassId),
		BrandId:  int(in.BrandId),
	}
	mysql.DB.Debug().Create(&furn)

	return &furnirpc.FurnAddResponse{
		FurnId: int64(furn.ID),
	}, nil
}
